package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.wxcomponent.parameter.UpdateChargeStatusBean;
import com.shop2cn.iapi.wxcomponent.service.UpdateChargeStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.YMTDateUtil;
/**
*mq消息通知（商家白名单变更）Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateChargeStatus{
	private static UpdateChargeStatusBean updatechargestatusBean;
	private static UpdateChargeStatusCall updatechargestatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("mq消息通知（商家白名单变更）Test");
	}

	@Before
	public void caseUp() {
		updatechargestatusBean=new UpdateChargeStatusBean();
		updatechargestatusCall=new UpdateChargeStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatechargestatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateChargeStatus_001() {
		Logger.start(true,"未付费-》无需付费 ， 成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            JsonObject getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
            Logger.verifyEquals(0, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
			updatechargestatusBean.setMchId(mchid);
			updatechargestatusBean.setWxApp(true);
			
			updatechargestatusCall.setData(updatechargestatusBean);
			updatechargestatusCall.callService();		
			Logger.verifyEquals("ok", updatechargestatusCall.getReturnData(), "返回");
			getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
			Logger.verifyEquals(2, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateChargeStatus_002() {
		Logger.start(true,"已付费-》无需付费  ,成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			
            JsonObject getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
            Logger.verifyEquals(1, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
			updatechargestatusBean.setMchId(mchid);
			updatechargestatusBean.setWxApp(true);
			
			updatechargestatusCall.setData(updatechargestatusBean);
			updatechargestatusCall.callService();		
			Logger.verifyEquals("ok", updatechargestatusCall.getReturnData(), "返回");
			getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
			Logger.verifyEquals(1, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateChargeStatus_003() {
		Logger.start(true,"已付费->无需付费->删除白名单->已付费  ,成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.AuthorizationCallBack(appid, "authorized");
            WxComponentService.Remark("aaa", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			
            JsonObject getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
            Logger.verifyEquals(1, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
			updatechargestatusBean.setMchId(mchid);
			updatechargestatusBean.setWxApp(true);
			updatechargestatusCall.setData(updatechargestatusBean);
			updatechargestatusCall.callService();		
			getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
			Logger.verifyEquals(1, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
			
			updatechargestatusBean.setMchId(mchid);
			updatechargestatusBean.setWxApp(false);
			updatechargestatusCall.setData(updatechargestatusBean);
			updatechargestatusCall.callService();
			Logger.verifyEquals("ok", updatechargestatusCall.getReturnData(), "返回");
			getMchChargeStatusAndMoney = WxComponentService.GetMchAppAllStatus(mchid);
			Logger.verifyEquals(1, getMchChargeStatusAndMoney.get("chargeStatus").getAsInt(), "判断chargeStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}